package com.jia.activity;

import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.widget.Toast;
import com.jia.R;

/**
 * @Author: xiuyajia
 * @Date: 11/27/13 2:27 PM
 */
public class ChangeCfgActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Configuration configuration = getResources().getConfiguration();
        //如果当前是横屏
        if (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
        //如果当前是竖屏
        if (configuration.orientation == Configuration.ORIENTATION_PORTRAIT) {
            this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }

    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        String screen = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE ? "屏幕横向" : "屏幕竖向";

        Toast.makeText(this, "系统屏幕方向发生改变\n修改后的屏幕方向为：" + screen, Toast.LENGTH_LONG);
        System.out.println(screen);
    }
}
